
$(document).ready(function(){
	AddBackgroundImg();
	wantB();
	wantAllCity();
	wantAllLine();
	
});
//请求所有城市接口
function wantAllCity(){	
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/cityinfo",
		data : {
			
		},
		contentType : "application/x-www-form-urlencoded;charset=utf-8",

		success : function(data) {
			var a = "";
			var a1 = "";
			for(var i = 0;i<data.data.datashot.length;i++){
				var a = a + "<div class=\"lineindex_banner_city_city_item\">"+data.data.datashot[i].city+"</div>";
				var a1 = a1 + "<div class=\"col-lg-6 col-md-6 lineindex_hot_left_item shand\">"+data.data.datashot[i].city+"</div>"
			}
			$("div.lineindex_banner_city_city:eq(0)").html(a);
			$("div.lineindex_hot_left").html(a1);
			var b = "";
			var b1 = "";
			for(var i = 0;i<data.data.datassea.length;i++){
				var b = b + "<div class=\"lineindex_banner_city_city_item\">"+data.data.datassea[i].city+"</div>";
				var b1 = b1 + "<div class=\"lineindex_sea_left_up_item\">"+data.data.datassea[i].city+"</div>"
			}
			$("div.lineindex_banner_city_city:eq(1)").html(b);
			$("div.lineindex_sea_left_up:eq(0)").html(b1);
			var c = "";
			var c1 = "";
			for(var i = 0;i<data.data.dataswind.length;i++){
				var c = c + "<div class=\"lineindex_banner_city_city_item\">"+data.data.dataswind[i].city+"</div>";
				var c1 = c1 + "<div class=\"lineindex_sea_left_up_item lineindex_sea_left_up_itemone\">"+data.data.dataswind[i].city+"</div>"
			}
			$("div.lineindex_banner_city_city:eq(2)").html(c);
			$("div.lineindex_sea_left_up:eq(1)").html(c1);
			var d="";
			var d1 = "";
			for(var i = 0;i<data.data.dataswater.length;i++){
				var d = d + "<div class=\"lineindex_banner_city_city_item\">"+data.data.dataswater[i].city+"</div>";
				var d1 = d1 + "<div class=\"lineindex_sea_left_up_item lineindex_sea_left_up_itemtwo\">"+data.data.dataswater[i].city+"</div>"
			}
			$("div.lineindex_banner_city_city:eq(3)").html(d);
			$("div.lineindex_sea_left_up:eq(2)").html(d1);
			/* $("#img"+i).attr("src",data.data[i-1].picture); */
			gotoList();
			//只有在生成结构之后才能对结构进行绑定事件
			
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//为城市添加跳转线路列表页动作
function gotoList(){
	for(var j = 0;j<4;j++){
		var a = $("div.lineindex_banner_city_city:eq("+j+")>div.lineindex_banner_city_city_item");		
		for(var i = 0;i<a.length;i++){
			$("div.lineindex_banner_city_city:eq("+j+")>div.lineindex_banner_city_city_item:eq("+i+")").click(function(j,i){
				return function(){
					console.log("i="+i);
					console.log("j="+j);
					var city = $(this).text();
					console.log("city="+city);
					var url = basePath+"/linelist?linecity="+city;
					url = encodeURI(url);
					url = encodeURI(url);
					window.location.href = (url);	
				}					
			}(j,i));
		}
	}
	var b = $("div.lineindex_hot_left_item");
	for(var i = 0;i<b.length;i++){
		$("div.lineindex_hot_left_item:eq("+i+")").click(function(i){
			return function(){
				var city = $(this).text();
				console.log("city="+city);
				var url = basePath+"/linelist?linecity="+city;
				url = encodeURI(url);
				url = encodeURI(url);
				window.location.href = (url);
			};
		}(i))
	}
	var c = $("div.lineindex_sea_left_up_item");
	for(var i = 0;i<c.length;i++){
		$("div.lineindex_sea_left_up_item:eq("+i+")").click(function(i){
			return function(){
				var city = $(this).text();
				console.log("city="+city);
				var url = basePath+"/linelist?linecity="+city;
				url = encodeURI(url);
				url = encodeURI(url);
				window.location.href = (url);
			}
		}(i))
	}
	
}
//请求所有线路详情接口
function wantAllLine(){
	var imgb=basePath+"/static/pcsofangche/line/lineindex/img/";
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/indexinfo",
		data : {
			
		},
		contentType : "application/x-www-form-urlencoded;charset=utf-8",

		success : function(data) {
			var a = "";
			for(var i = 0;i < data.data.datashot.length;i++){
				a = a + 
				"<div class=\"col-lg-3 col-md-3 lineindex_hot_center_item shand\">\n" +
				"<div class=\"lineindex_hot_center_item_icon\">\n" +
				"<img src=\""+data.data.datashot[i].picture+"\" class=\"lineindex_hot_center_item_icon_posi img-responsive\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city_icon\">\n" +
				"<img src=\""+imgb+"lineindex_city_small.png\" class=\"lineindex_hot_center_item_center_city_icon_posi\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_word\">出发地：</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_city\">"+data.data.datashot[i].city+"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_price_one\">起</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_two\">"+data.data.datashot[i].price+"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_three\">￥</div>\n" +
				"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_title\">"+data.data.datashot[i].title+"</div>\n" +
				"</div>"+"<font class=\"hidden\">"+data.data.datashot[i].lineid+"</font>"
				
			}
			$("div.lineindex_hot_center:eq(0)").html(a);
			var b = "";
			for(var i = 0;i < data.data.datassea.length;i++){
				b = b + 
				"<div class=\"col-lg-3 col-md-3 lineindex_hot_center_item shand\">\n" +
				"<div class=\"lineindex_hot_center_item_icon\">\n" +
				"<img src=\""+data.data.datassea[i].picture+"\" class=\"lineindex_hot_center_item_icon_posi img-responsive\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city_icon\">\n" +
				"<img src=\""+imgb+"lineindex_city_small.png\" class=\"lineindex_hot_center_item_center_city_icon_posi\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_word\">出发地：</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_city\">"+data.data.datassea[i].city+"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_price_one\">起</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_two\">"+data.data.datassea[i].price+"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_three\">￥</div>\n" +
				"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_title\">"+data.data.datassea[i].title+"</div>\n" +
				"</div>"+"<font class=\"hidden\">"+data.data.datassea[i].lineid+"</font>"
				
			}
			$("div.lineindex_hot_center:eq(1)").html(b);
			var c = "";
			for(var i = 0;i < data.data.dataswind.length;i++){
				c = c + 
				"<div class=\"col-lg-3 col-md-3 lineindex_hot_center_item shand\">\n" +
				"<div class=\"lineindex_hot_center_item_icon\">\n" +
				"<img src=\""+data.data.dataswind[i].picture+"\" class=\"lineindex_hot_center_item_icon_posi img-responsive\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city_icon\">\n" +
				"<img src=\""+imgb+"lineindex_city_small.png\" class=\"lineindex_hot_center_item_center_city_icon_posi\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_word\">出发地：</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_city\">"+data.data.dataswind[i].city+"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_price_one\">起</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_two\">"+data.data.dataswind[i].price+"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_three\">￥</div>\n" +
				"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_title\">"+data.data.dataswind[i].title+"</div>\n" +
				"</div>"+"<font class=\"hidden\">"+data.data.dataswind[i].lineid+"</font>"
				
			}
			$("div.lineindex_hot_center:eq(2)").html(c);
			var d = "";
			for(var i = 0;i < data.data.dataswater.length;i++){
				d = d + 
				"<div class=\"col-lg-3 col-md-3 lineindex_hot_center_item shand\">\n" +
				"<div class=\"lineindex_hot_center_item_icon\">\n" +
				"<img src=\""+data.data.dataswater[i].picture+"\" class=\"lineindex_hot_center_item_icon_posi img-responsive\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city_icon\">\n" +
				"<img src=\""+imgb+"lineindex_city_small.png\" class=\"lineindex_hot_center_item_center_city_icon_posi\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_word\">出发地：</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_city\">"+data.data.dataswater[i].city+"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_price_one\">起</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_two\">"+data.data.dataswater[i].price+"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_three\">￥</div>\n" +
				"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_title\">"+data.data.dataswater[i].title+"</div>\n" +
				"</div>"+"<font class=\"hidden\">"+data.data.dataswater[i].lineid+"</font>"
				
			}
			$("div.lineindex_hot_center:eq(3)").html(d);		
			gotoInfo();
			//只有在生成结构之后才能对结构进行绑定事件
			
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
			layer.close(LoadingIcon);
		},
	});
}
//为所有跳转线路详情页添加动作
function gotoInfo(){
	var a = $("div.lineindex_hot_center>div.lineindex_hot_center_item");
	for(var i = 0;i<a.length;i++){
			$("div.lineindex_hot_center>div.lineindex_hot_center_item:eq("+i+")").click(function(i){
				return function(){
					var lineid =  $("div.lineindex_hot_center>font:eq("+i+")").text();
					var linecity = $("div.lineindex_hot_center>div.lineindex_hot_center_item:eq("+i+") div.lineindex_hot_center_item_center_city_city:eq(0)").text();
					console.log("lineid="+lineid);
					console.log("linecity="+linecity);
					var url = basePath+"/lineinfo?lineid="+lineid+"&linecity="+linecity;
					url = encodeURI(url);
					url = encodeURI(url);
					window.location.href = (url);
				}				
			}(i));	
	}
}
//请求线路首页banner
function wantB(){
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/bannar",
		data : {
			
		},
		contentType : "application/x-www-form-urlencoded;charset=utf-8",

		success : function(data) {
			$("img#bannerimg1").attr("src",data.data[0].picture);
			var a = "";
			var b = "";
			for(var i = 1;i<data.data.length;i++){
				a = a + "<li data-target=\"#indexbanner\" data-slide-to=\""+i+"\"></li>";
				b = b + "<div class=\"item\">\n"+
						"<img src=\""+data.data[i].picture+"\" alt=\"Second slide\" class=\"img-responsive\" id=\"bannerimg"+(i+1)+"\" />\n"+
						"</div>\n"+
						"</div>";
			};
//			$("ol.carousel-indicators>li:eq(0)").after(a);
			$("div.carousel-inner>div.item:eq(0)").after(b);
			
			//只有在生成结构之后才能对结构进行绑定事件
			
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//为面朝大海，名山胜水，民俗风情设置背景图片
function AddBackgroundImg(){
	var imgb=basePath+"/static/pcsofangche/line/lineindex/img/";
	$("div.lineindex_sea_left:eq(0)").css("background-image","url("+imgb+"lineindex_sea_big.png");
	$("div.lineindex_sea_left:eq(1)").css("background-image","url("+imgb+"lineindex_wind_big.png");
	$("div.lineindex_sea_left:eq(2)").css("background-image","url("+imgb+"lineindex_water_big.png");
}